package com.wang.rabbitmqstudy.consumer;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 测试 (reject || nack) && requeue=false进入死信队列
 */
@Component
public class CommonQueueHandler {
    @RabbitListener(queues = {"argumentsCommonQueue"})
    @RabbitHandler
    public void execute(Channel channel, Message message) throws InterruptedException, IOException {
        System.out.println(new String(message.getBody()));
//        channel.basicReject(message.getMessageProperties().getDeliveryTag(),false);
        channel.basicNack(message.getMessageProperties().getDeliveryTag(),false,false);
    }
}
